package com.yycx.module.bus.provider.handler.haiying.tasktodo.settle.invoice;

import com.yycx.common.base.entity.EntityMap;
import com.yycx.common.base.utils.FlymeUtils;
import com.yycx.common.mybatis.interceptor.GetInterceptor;
import com.yycx.common.mybatis.model.ResultBody;
import com.yycx.common.mybatis.query.CriteriaQuery;
import com.yycx.module.bus.client.entity.BusInvoiceunit;
import com.yycx.module.bus.client.entity.BusPayment;
import com.yycx.module.bus.client.entity.hy.BusHyorderInovice;
import com.yycx.module.bus.provider.service.BusInvoiceunitService;
import com.yycx.module.bus.provider.service.hy.BusHyorderInoviceService;
import com.yycx.module.file.provider.service.SysFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 获取税金支付信息详情
 *
 * @author zyf
 */
@Component
public class HyInvoicePayInfoGetHandler implements GetInterceptor {

    @Autowired
    private BusInvoiceunitService invoiceunitService;
    @Autowired
    private BusHyorderInoviceService hyorderInoviceService;

    @Override
    public ResultBody validate(CriteriaQuery cq, EntityMap params) {
        return ResultBody.ok();
    }

    @Override
    public void prepare(CriteriaQuery cq, EntityMap entityMap) {
        cq.select(BusPayment.class, "*");
    }

    @Override
    public void complete(CriteriaQuery cq, EntityMap map) {
        Long invoiceUnitId = map.getLong("invoiceUnitId");
        if (FlymeUtils.isNotEmpty(invoiceUnitId)) {
            BusInvoiceunit invoiceunit = invoiceunitService.getById(invoiceUnitId);
            map.put("invoiceUnitId", invoiceunit.getInvoiceUnitId());
            map.put("invoiceUnitName", invoiceunit.getInvoiceunitName());
            map.put("bankName", invoiceunit.getBankName());
            map.put("bankNo", invoiceunit.getBankNo());
            map.put("contractDate", invoiceunit.getContractDate());
        }
        Long invoiceId = map.getLong("invoiceId");
        if(FlymeUtils.isNotEmpty(invoiceId)){
            BusHyorderInovice hyorderInovice=hyorderInoviceService.getById(invoiceId);
            map.put("invoiceDate", hyorderInovice.getInvoiceDate());
        }
    }
}
